#include <stdio.h>

#define MAX_STACKS 50

#define get_int(n) scanf("%d", &(n))


int main ()
{
	int set, stacks, min_moves, s[MAX_STACKS], i, h_average, h;

	set = 1;
	get_int(stacks);
	while (stacks)
	{
		printf("Set #%d\n", set);

		h_average = 0;
		for (i = 0; i < stacks; ++i) {
			get_int(h);
			s[i] = h;
			h_average += h;
		}
		h_average /= stacks;

		min_moves = 0;
		for (i = 0; i < stacks; ++i) {
			h = s[i];
			if (h > h_average)
				min_moves += h - h_average;
		}

		printf("The minimum number of moves is %d.\n\n", min_moves);

		++set;
		get_int(stacks);
	}


	return 0;
}